<template>
  <div style="margin-left: 300px">
    <div style="height: 100px; font-size: 30px; margin-top: 30px">
      创建 Pull Request
    </div>
    <div>
      <div style="display: inline-block">
        <div style="font-size: 20px">源分支</div>
        <div style="display: flex">
          <el-select
            v-model="shousename"
            class="selectshouse"
            size="large"
            disabled
            style="width: 150px; margin-top: 10px; margin-right: 3px"
          >
          </el-select>
          <el-select
            v-model="sBranch"
            class="selectsBranch"
            placeholder="Select"
            size="large"
            style="width: 300px; margin-top: 10px"
            @change="selectsBranch"
          >
            <el-option
              v-for="item in branchs"
              :key="item"
              :label="item"
              :value="item"
            />
          </el-select>
        </div>
      </div>
      <div style="display: inline-block">
        <!-- <el-icon size="large" style="width: 40px"><Right /></el-icon> -->
        <img
          src="@/assets/箭头.jpg"
          style="height: 20px; width: 60px; margin-bottom: 0"
        />
      </div>
      <div style="display: inline-block">
        <div style="font-size: 20px">目标分支</div>
        <div style="display: flex">
          <el-select
            v-model="tusername"
            class="selecttusername"
            size="large"
            style="width: 150px; margin-top: 10px; margin-right: 3px"
            @click="selecttuser"
          >
            <el-option
              v-for="item in tusernames"
              :key="item"
              :label="item"
              :value="item"
              >{{ item }}/{{ this.$route.params.housename }}</el-option
            >
          </el-select>
          <el-select
            v-model="tBranch"
            class="selecttBranch"
            placeholder="Select"
            size="large"
            background
            style="
              width: 300px;
              margin-right: 20px;
              margin-top: 10px;
              margin-bottom: 10px;
            "
            @change="selecttBranch"
          >
            <el-option
              v-for="item in tbranchs"
              :key="item"
              :label="item"
              :value="item"
            />
          </el-select>
        </div>
      </div>
    </div>
    <div class="message">必须选择不同的分支</div>
    <div style="margin-top: 30px; margin-right: 400px">
      <span>Pull Request信息</span>
      <span
        ><el-input
          v-model="descripe"
          size="large"
          style="margin-top: 20px"
        ></el-input
      ></span>
    </div>
    <div></div>
    <div>
      <el-button
        @click="newpr"
        size="large"
        style="margin-top: 60px; width: 300px"
        >新建</el-button
      >
    </div>
  </div>
</template>
<script>
import { ElMessage } from "element-plus";
import request from "@/utils/request";
export default {
  name: "NewPullRequest",
  data() {
    return {
      shousename:
        this.$route.params.username + "/" + this.$route.params.housename,
      tusername: "",
      tusernames: [],
      branchs: [],
      tbranchs: [],
      sBranch: "",
      tBranch: "",
      descripe: "",
    };
  },
  mounted() {
    request
      .get(
        `/branch/getAllBranch?username=${this.$route.params.username}&housename=${this.$route.params.housename}`
      )
      .then((res) => {
        if (res.code == 200) {
          console.log(res);
          this.branchs = res.data;
          this.sBranch = res.data[0];
        } else {
          console.log("获取分支信息失败");
        }
      });
    this.getusernames();
  },
  methods: {
    getusernames() {
      request
        .get(
          "/status/getPRuser?houseowner=" +
            this.$route.params.username +
            "&housename=" +
            this.$route.params.housename
        )
        .then((res) => {
          if (res.code == 200) {
            this.tusernames = res.data;
            this.tusername = res.data[0];
            this.selecttuser();
          } else {
            console.log(res.message);
          }
        });
    },
    selecttuser() {
      request
        .get(
          `/branch/getAllBranch?username=${this.tusername}&housename=${this.$route.params.housename}`
        )
        .then((res) => {
          if (res.code == 200) {
            console.log(res);
            this.tbranchs = res.data;
            this.tBranch = res.data[0];
          } else {
            console.log("获取分支信息失败");
          }
        });
    },
    newpr() {
      console.log(this.sBranch);
      console.log(this.tBranch);
      console.log(this.descripe);
      request
        .get(
          "/status/PR?houseowner=" +
            this.$route.params.username +
            "&housename=" +
            this.$route.params.housename +
            "&source=" +
            this.sBranch +
            "&target=" +
            this.tBranch +
            "&targethouseowner=" +
            this.tusername
        )
        .then((res) => {
          if (res.code == 200) {
            ElMessage({
              showClose: true,
              message: res.message,
              type: "success",
            });
          } else {
            ElMessage({
              showClose: true,
              message: res.message,
              type: "error",
            });
          }
        })
        .catch((error) => {
          ElMessage({
            showClose: true,
            message: "ERROR",
            type: "error",
          });
        });
    },
  },
};
</script>

<style scope>
.message {
  -webkit-text-size-adjust: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Liberation Sans",
    "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Wenquanyi Micro Hei",
    "WenQuanYi Zen Hei", "ST Heiti", SimHei, SimSun, "WenQuanYi Zen Hei Sharp",
    sans-serif;
  -webkit-font-smoothing: antialiased;
  text-align: left;
  width: 78%;
  box-sizing: inherit;
  position: relative;
  min-height: 1em;
  margin: 1em 0em;
  padding: 1em 1.5em;
  line-height: 1.4285em;
  transition: opacity 0.1s ease, color 0.1s ease, background 0.1s ease,
    box-shadow 0.1s ease, -webkit-box-shadow 0.1s ease;
  font-size: 1em;
  border-radius: 4px;
  border: 1px solid #e3e9ed;
  background: #fff;
  margin-bottom: 10px;
  background-color: #ffe8e6;
  color: #db2828;
  box-shadow: 0px 0px 0px 1px #db2828 inset, 0px 0px 0px 0px rgba(0, 0, 0, 0);
  margin-top: 0px;
}
</style>
